cssjshtml vue.js 组件嵌套demo

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 4724

2019/01/07 18:15


components/Users.vue

<template>

  <div class="users">
    <h1>hello users</h1>
    <ul>
      <li v-for="user in users"
      v-on:click="user.show=!user.show">
       <h2>{{user.name}}</h2>
        <h3 v-show="user.show">{{user.position}}</h3>
      </li>
    </ul>
  </div>
</template>

<script>
  export default {
    name: "users",
    data() {
      return {users:[
          {name:"brownwang",position:"运维开发",show:false},
          {name:"brownwang",position:"运维开发",show:false},

          {name:"brownwang",position:"运维开发",show:false},
          {name:"brownwang",position:"运维开发",show:false},
          {name:"brownwang",position:"运维开发",show:false}]
      }
    }
  }
</script>

<style scoped>
.users{
  width:100%;
  max-width:1200px;
  margin:40px auto;
  padding:0 20px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
  ul{
    display:flex;
    flex-wrap:wrap;
    list-style-type:none;
    padding:0;
  }
  li{
    flex-grow:1;
    flex-basis:200px;
    text-align:center;
    padding:30px;
    border:1px solid #222;
    margin:10px;
  }
</style>

components/Header.vue

<template>
 <header>
   <h1>{{title}}</h1>
 </header>
</template>

<script>
export default {
  name: 'app-header',
  data () {
    return {
      title:'Vue.js Demo'
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  header{
    background:lightgreen;
    padding:10px;
  }
  h1{
    color:#222;
    text-align:center;
  }
</style>

components/Footer.vue

<template>
 <footer>
   <p>{{copyright}}</p>
 </footer>
</template>

<script>
export default {
  name: 'app-footer',
  data () {
    return {
      copyright:'Copyright 2019 Vue Demo'
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  footer{
    background:#222;
    padding:6px;
  }
  p{
    color:lightgreen;
    text-align:center;
  }
</style>

App.vue

<!-- 1模板:html结构 -->
<template>
  <div id="app">
    <app-header></app-header>
    <users></users>
    <app-footer></app-footer>
  </div>
</template>

<!-- 2行为:逻辑处理 -->
<script>
  // 局部注册组件
  import Users from './components/Users'
  import Header from './components/Header'
  import Footer from './components/Footer'

  export default {
    name: 'App',
    data() {
      return {
        title: "这是一个干净的脚手架项目!"
      }
    },
    components: {
      "users": Users,
      "app-header": Header,
      "app-footer": Footer

    }
  }
</script>

<!-- 3样式:解决样式 -->
<style scoped>
  h1 {
    color: purple;
  }
</style>

 

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1